package com.sunseaypw.console;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component //bean的id/name缺省为 类名首字母小写 springBean
@Scope("prototype") 
public class SpringBean {
    User u=null;
    @Autowired
    @Qualifier("userService")
    public void setUser(User u){
        this.u=u;
    }
    public User getUser(){
        return this.u;
    }
    @PostConstruct
    void init(){
        System.out.println("spring bean 构建后初始化事件！！");
    }
    @PreDestroy
    void destroy(){//prototype 构建后分配给caller后就失去ioc容器的托管了，所以后事件无法触发！！
        System.out.println("spring bean 销毁前清理事件！！");
    }
}
